var _util = _interopRequireDefault(require("../../public/utils/util"));

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

function _objectSpread(e) {
    for (var t = 1; t < arguments.length; t++) {
        var a = null != arguments[t] ? arguments[t] : {}, n = Object.keys(a);
        "function" == typeof Object.getOwnPropertySymbols && (n = n.concat(Object.getOwnPropertySymbols(a).filter(function(t) {
            return Object.getOwnPropertyDescriptor(a, t).enumerable;
        }))), n.forEach(function(t) {
            _defineProperty(e, t, a[t]);
        });
    }
    return e;
}

function _defineProperty(t, e, a) {
    return e in t ? Object.defineProperty(t, e, {
        value: a,
        enumerable: !0,
        configurable: !0,
        writable: !0
    }) : t[e] = a, t;
}

var TRANSFORM_TIME = [ {
    id: 1,
    name: "全部"
}, {
    id: 2,
    name: "今日"
}, {
    id: 3,
    name: "本周"
}, {
    id: 4,
    name: "本月"
}, {
    id: 5,
    name: "近半年"
} ];

Component({
    properties: {
        top: {
            type: String,
            value: "0px"
        },
        name: String
    },
    data: {
        shown: !1,
        start: "",
        end: "",
        TRANSFORM_TIME: TRANSFORM_TIME
    },
    methods: {
        show: function() {
            this.setData({
                shown: !0
            }), this.data.start || this.timeChangeSet(TRANSFORM_TIME[0].id);
        },
        onTrigger: function() {
            this.setData({
                shown: !this.data.shown
            });
        },
        onTimeChange: function(t) {
            var e = t.detail.value, a = t.currentTarget.dataset.name;
            this.setData(_defineProperty({
                value: ""
            }, a, e));
        },
        selectTime: function(t) {
            var e = t.detail;
            this.timeChangeSet(e.id);
        },
        timeChangeSet: function(t) {
            var e, a = new Date(), n = this.getDate(a), r = n;
            switch (t) {
              case 1:
                e = "2018-01-01";
                break;

              case 2:
                e = n;
                break;

              case 3:
                a.setDate(a.getDate() - [ 1, 2, 3, 4, 5, 6, 0 ].indexOf(a.getDay())), e = this.getDate(a);
                break;

              case 4:
                e = n.replace(/\d\d$/, "01");
                break;

              case 5:
                a.setMonth(a.getMonth() - 6), e = this.getDate(a);
            }
            this.setData({
                value: t,
                start: e,
                end: r
            });
        },
        getDate: function(t) {
            var e = t.getFullYear(), a = _util.default.formatNumber(t.getMonth() + 1), n = _util.default.formatNumber(t.getDate());
            return "".concat(e, "-").concat(a, "-").concat(n);
        },
        resetTime: function(t) {
            var n = this;
            !(1 < arguments.length && void 0 !== arguments[1]) || arguments[1];
            this.timeChangeSet(TRANSFORM_TIME[0].id), this.setData({
                shown: !1
            }, function() {
                var t = n.data, e = t.start, a = t.end;
                n.triggerEvent("reset", _objectSpread({
                    start: e,
                    end: a
                }, TRANSFORM_TIME[0]));
            });
        },
        confirmTime: function() {
            var r = this;
            this.setData({
                shown: !1
            }, function() {
                var t = r.data, e = t.start, a = t.end, n = t.value;
                r.triggerEvent("confirm", _objectSpread({
                    start: e,
                    end: a
                }, TRANSFORM_TIME.find(function(t) {
                    return t.id === n;
                })));
            });
        }
    }
});